package cn.zhiran.org.service.impl;

import cn.zhiran.org.domain.Department;
import cn.zhiran.org.mapper.DepartmentMapper;
import cn.zhiran.org.query.DepartmentQuery;
import cn.zhiran.org.service.IDepartmentService;
import cn.zhiran.org.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DepartmenServiceImpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;
    @Override
    public List<Department> loadAll() {
        return departmentMapper.loadAll();
    }

    @Override
    public Department loadById(Long id) {

        return departmentMapper.loadById(id);
    }

    @Transactional
    @Override
    public void delete(Long id) {
        departmentMapper.delete(id);
    }

    @Transactional
    @Override
    public void update(Department department) {
        departmentMapper.update(department);
    }

    @Transactional
    @Override
    public void insert(Department department) {
        departmentMapper.insert(department);
    }


    @Override
    public PageList<Department> queryData(DepartmentQuery query) {
        //总条数
        Integer totals = departmentMapper.queryCount(query);
        if(totals==0){
            return new PageList<>();
        }
        //每页数据
        List<Department> rows = departmentMapper.queryData(query);
        return new PageList<>(totals,rows);
    }
}
